<template>
    <div class="photoinfo-container">
        <h3>标题{{ photoinfo.title }}</h3>
        <p class="subtitle">
            <span>发表时间: {{ photoinfo.add_time | dateFormat}}</span>
            <span>点击 {{ photoinfo.click }}次</span>
        </p>
        <hr>
        <!--缩略图-->
        <vue-preview :slides="list" @close="handleClose"></vue-preview>
        <!--        图片内容区域-->
        <div class="content" v-html=" photoinfo.content "></div>
        <!--        评论子组件-->
        <cms-box :id="this.id"></cms-box>
    </div>
</template>

<script>
    // 导入评论子组件
    import comment from '../subcompontents/comment.vue'

    export default {
        data() {
            return {
                id: this.$route.params.id,
                photoinfo: {},
                list: []
            }
        },
        created() {
            this.getPhotoInfo(),
                this.getThumbs()
        },
        methods: {
            getPhotoInfo() {
                // 获取图片的详情
                this.$http.get("api/getimageinfo/" + this.id).then(result => {
                    console.log(result.body.message);
                    if (result.body.status === 0) {
                        console.log("渲染")
                        this.photoinfo = result.body.message[0]
                        console.log("ememem")
                    }
                })
            },
            getThumbs() {
                this.$http.get('api/getthumimages/' + this.id).then(result => {
                    console.log(result.body.message);
                    if (result.body.status === 0) {
                        // 循环每个图片数据，补全图片的长和宽
                        result.body.message.forEach(item => {
                            item.w = 600;
                            item.h = 400;
                            item.msrc = item.src;
                        })
                        // 把数据保存到list
                        this.list = result.body.message;
                    }
                })
            },
            handleClose(){
                console.log("干嘛升级")
            }

        },
        // 注册子组件
        components: {
            'cms-box': comment
        }
    }
</script>

<style lang="less" scoped>
    .photoinfo-container {
        padding: 3px;

        h3 {
            color: #26A2FF;
            font-size: 15px;
            margin: 15px 0;
            text-align: center;
        }

        .subtitle {
            display: flex;
            justify-content: space-between;
            font-size: 13px;
        }

        .content {
            font-size: 13px;
            line-height: 25px;
        }

    }
</style>